namespace XEAS.Framework.ShellLib
{
    using System;
    using System.Runtime.InteropServices;

    public class ShellFunctions
    {
        public static IShellFolder GetDesktopFolder()
        {
            IntPtr ptr;
            ShellApi.SHGetDesktopFolder(out ptr);
            Type t = Type.GetType("XEAS.Framework.ShellLib.IShellFolder");
            return (IShellFolder) Marshal.GetTypedObjectForIUnknown(ptr, t);
        }

        public static Type GetFolderFilterSiteType()
        {
            return Type.GetType("XEAS.Framework.ShellLib.IFolderFilterSite");
        }

        public static Type GetFolderFilterType()
        {
            return Type.GetType("XEAS.Framework.ShellLib.IFolderFilter");
        }

        public static IMalloc GetMalloc()
        {
            IntPtr ptr;
            ShellApi.SHGetMalloc(out ptr);
            return (IMalloc) Marshal.GetTypedObjectForIUnknown(ptr, GetMallocType());
        }

        public static Type GetMallocType()
        {
            return Type.GetType("XEAS.Framework.ShellLib.IMalloc");
        }

        public static IShellFolder GetShellFolder(IntPtr ptrShellFolder)
        {
            Type shellFolderType = GetShellFolderType();
            return (IShellFolder) Marshal.GetTypedObjectForIUnknown(ptrShellFolder, shellFolderType);
        }

        public static Type GetShellFolderType()
        {
            return Type.GetType("XEAS.Framework.ShellLib.IShellFolder");
        }
    }
}

